package com.mhxy.service.impl;

import com.mhxy.constant.PicConstants;
import com.mhxy.service.AbstractTask;
import com.mhxy.util.FuzzyPicUtil;
import com.sun.jna.platform.win32.WinDef;
import lombok.extern.slf4j.Slf4j;

/**
 * 领取双倍点数任务
 */
@Slf4j
public class ReceivePointTaskImpl extends AbstractTask {

    public ReceivePointTaskImpl(WinDef.HWND hwnd_0) {
        super(hwnd_0);
    }

    @Override
    public String getTaskName() throws Exception {
        return "领取双倍";
    }

    @Override
    public Boolean before() throws Exception {
        clickEsc1();
        if (FuzzyPicUtil.findPic(hwnd_0, PicConstants.公共_挂机, 2).isFinded()) {
            return true;
        }
        return goToJianYe();
    }

    @Override
    public Boolean execute() throws Exception {
        if (!FuzzyPicUtil.findAndClickRandom(hwnd_0, PicConstants.公共_挂机, 3)) {
            return false;
        }
        for (int j = 0; j < 5; j++) {
            FuzzyPicUtil.findAndClickRandom(hwnd_0, PicConstants.抓鬼任务_领取点数, 1);
        }
        // 如果点数不够，点击取消
        FuzzyPicUtil.findAndClickRandom(hwnd_0, PicConstants.抓鬼任务_领取点数取消, 3);
        // 退出界面
        clickEsc1();
        return true;
    }

    @Override
    public Boolean after() throws Exception {
        return true;
    }
}
